package P025_Round;

import org.junit.Test;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 四舍五入
 *
 */
public class Round {

    @Test
    public void Test1() {
        System.out.println(Math.round(10.5));
        System.out.println(Math.round(-10.5));
    }

    @Test
    public void Test2() {
        Double lossMoney = 0.000D + 0.001D + 0.002D + 0.003D + 0.004D - 0.005D - 0.004D - 0.003D - 0.002D - 0.001D;
        System.out.println("平均每十个账户损失:"+lossMoney);

        int account = 50000000;

        System.out.println("银行每年损失:" + 0.005D * account *4 / 10);
    }

    @Test
    public void Test3() {
        //本金
        BigDecimal principal = new BigDecimal(1000000);
        //利率
        BigDecimal interest = new BigDecimal(0.001875225*3);
        //本息
        BigDecimal total = principal.multiply(interest).setScale(6, RoundingMode.HALF_EVEN);
        System.out.println(total);
    }


}
